<template>
  <PageWrapper title="标签列表">
    <!-- <DeptTree class="w-1/4 xl:w-1/5" @select="handleSelect" /> -->
    <BasicTable @register="registerTable">
      <template #toolbar>
        <!-- v-auth="['10032', RoleEnum.SUPER]"  -->
        <a-button type="primary" @click="handleCreate">添加</a-button>
      </template>
      <template #account="{ record }">
        <a @click="titleClick($event, record)">{{ record.account }}</a>
      </template>
      <!-- auth: ['10033', RoleEnum.SUPER], -->

      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'clarity:note-edit-line',

              onClick: handleEdit.bind(null, record),
              label: '',
            },
            {
              icon: 'ant-design:delete-outlined',
              color: 'error',
              label: '',

              popConfirm: {
                title: '确认删除该标签吗?',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
    <GroupModal @register="registerModal" @success="handleSuccess" />
  </PageWrapper>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';

  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { deleteGroup, deleteLabel, getLabelList } from '/@/api/sys/user';
  import { PageWrapper } from '/@/components/Page';
  // import DeptTree from './DeptTree.vue';

  import { useModal } from '/@/components/Modal';

  import { columns } from './group.data';
  import GroupModal from './GroupModal.vue';
  import { useUserStoreWithOut } from '/@/store/modules/user';
  import { RoleEnum } from '/@/enums/roleEnum';

  export default defineComponent({
    name: 'UserList',
    components: { BasicTable, PageWrapper, TableAction, GroupModal },
    setup() {
      const [registerModal, { openModal }] = useModal();
      const userStore = useUserStoreWithOut();
      const [registerTable, { reload }] = useTable({
        // title: '账号列表',
        api: getLabelList,
        columns,
        searchInfo: {
          pid: userStore.getUserInfo.id,
        },
        indexColumnProps: {
          width: 80,
        },
        useSearchForm: false,
        showTableSetting: false,
        bordered: true,
        actionColumn: {
          width: 90,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });

      function handleCreate() {
        openModal(true, {
          isUpdate: false,
        });
      }

      function handleEdit(record: Recordable) {
        openModal(true, {
          record,
          isUpdate: true,
        });
      }

      function handleDelete(record: Recordable) {
        deleteLabel(record.id).then(
          () => {
            // msg
            handleSuccess();
          },
          () => {},
        );
      }

      function handleSuccess() {
        reload();
      }

      // 点击图像相机编号事件，与行点击事件区分开，
      function titleClick(e: PointerEvent, item) {
        e.stopPropagation();
        openModal(true, {
          data: item,
        });
        // 弹框展示当前图像信息
      }

      return {
        titleClick,
        registerTable,
        registerModal,
        handleCreate,
        handleEdit,
        handleDelete,
        handleSuccess,
        RoleEnum,
      };
    },
  });
</script>
